﻿using iemtm.WeChat.Core;
using iemtm.WeChat.Core.Managers;
using iemtm.WeChat.Web.Entry.Areas.Admin.Model;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace iemtm.WeChat.Web.Entry.Areas.Admin.Controllers
{
    [Area("Admin")]
    [Route("/[controller]/[action]")]
    public class AnnouceAuditController : Controller
    {
        private readonly IWorkManager _workManager;
      //  private readonly IUserManager _userManager;
      //  private readonly IGeneratorManager _generatorManager;
        private readonly IInfoManager _infoManager;

        public AnnouceAuditController(IWorkManager workManager
          //  , IUserManager userManager
          //   , IGeneratorManager generatorManager
             , IInfoManager infoManager
            )
        {
            _workManager = workManager;
          //  _userManager = userManager;
           // _generatorManager = generatorManager;
            _infoManager = infoManager;
        }

        /// <summary>
        /// 工单列表页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 审核页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Audit()
        {
            return View();
        }

        /// <summary>
        /// 工单详情页面
        /// </summary>
        /// <param name="annouceCode"></param>
        /// <returns></returns>
        public async Task<ActionResult> Detail(string annouceCode)
        {
            AnnouceAuditDetailModel model = new AnnouceAuditDetailModel();
            var LoginInfo = _workManager.CurrentUser;
            model.AnnounceList =await _infoManager.GetAnnFirstOrDefaultAsync(c => c.AnnounceCode == annouceCode && c.PrjCode == LoginInfo.PrjCode);
            model.AnnouceStatus = (await _infoManager.GetCommTypeFirstOrDefaultAsync(c => c.TabName == "AnnounceStatus" && c.DicValue == model.AnnounceList.AnnounceStatus.ToString())).DicType;
            model.AnnFee = await _infoManager.GetAnnFeeFirstAsync(c => c.AnnounceCode == annouceCode);
            model.BaseStationTTCode = (await _infoManager.GetBaseStationFirstAsync(c => c.BaseStationCode == model.AnnounceList.BaseStationCode && c.PrjCode == LoginInfo.PrjCode)).BaseStationTTCode;
            if (model.AnnounceList.RegisteredGenset != null)
            {
                var Gen = MemoryEntity.gBuffGen.All.Values.FirstOrDefault(c => c.GeneratorCode == model.AnnounceList.RegisteredGenset);
                model.GensetNum = Gen.GensetNum ?? model.AnnounceList.RegisteredGenset;
            }

            return View(model);
        }

    }
}
